package com.sali.b_design_pattern.g_singleton_pattern.lesson_singleton.c_registration_form.map;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @description:
 * @date: 2023/3/19 14:03.
 * @version: 1.0
 */
public class ContainSingleton {

    private ContainSingleton() {
    }

    private static Map<String, Object> ioc = new ConcurrentHashMap<>();

    static {
        ioc.put(HelloEntity.class.getName(), new HelloEntity());
    }


    public static Object getBean(String className) {
        synchronized (ioc) {
            if (!ioc.containsKey(className)) {
                Object object = null;
                try {
                    object = Class.forName(className);
                    ioc.put(className, object);
                } catch (Exception ignore) {
                }
                return object;
            } else {
                return ioc.get(className);
            }
        }
    }

}
